import request from '../utils/request'

/**
 * 批量引入api
 */
let importApis = require.context('./modules', false, /\.(js|ts)$/)

//获取文件名
let patten = new RegExp(/^(\.{0,2}\/)*([\w]*\/)*([\w-_]*)(\.(js|ts))$/)

let ApiModules = importApis.keys().reduce((arr, path) => {
	//正则 取name
	patten.exec(path)
	let name = 'data';
	//获取所有接口列表
	let apis = (importApis(path).default || importApis(path)).reduce((arr, e, i) => {
		return arr[e.native] = (params) => request(e.remote, e.method, params), arr
	}, {});
	return arr[RegExp.$3] = apis, arr
}, {})

export default ApiModules;
